# -*- coding:utf-8 -*-
from runtime.utils.msg_tools import get_msg
from runtime.pkg.views import get_pkg

class Event():
	def __init__(self, request):
		self.__request = request
		self.msg_get = get_msg(request)
		self.from_user = self.__get_user()
		self.event_type = self.__get_event_type()


	def __get_event_type(self):
		event_type = self.msg_get.Event.text
		return event_type
	def __get_user(self):
		from_user = self.msg_get.FromUserName.text
		return from_user

	def handler(self):
		if self.event_type == 'subscribe':
			pkg_name = get_pkg('subs')
			print pkg_name
			if pkg_name:
				pkg_name += '.views'
				try:
					pkg_object = __import__(pkg_name, fromlist=['run'])
					msg_content = pkg_object.run(self.__request, type='event')
				except AttributeError:
						msg_content = {
							'msg_type': 'text',
							'content': 'AttributeError',
						}
				return msg_content
